﻿using System;
using System.Reflection;

namespace Gangleri.Enums
{
    public static class EnumExtensions
    {
        public static string GetStringValue(this Enum enumValue)
        {
            Type type = enumValue.GetType();

            FieldInfo fieldInfo = type.GetField(enumValue.ToString());

            StringValueAttribute[] attribs = fieldInfo.GetCustomAttributes(
                typeof(StringValueAttribute), false) as StringValueAttribute[];

            if (attribs.Length > 0)
            {
                return attribs[0].StringValue;
            }
            else
            {
                return fieldInfo.Name;
            }
        }
    }
}



